﻿package com.tudou.skin.common.behavior
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class AutoCloseUtil extends Object
    {

        public function AutoCloseUtil()
        {
            return;
        }// end function

        public static function actBehavior(param1:IAutoClose) : void
        {
            var listener:InteractiveObject;
            var rollOverHlr:Function;
            var rollOutHlr:Function;
            var timerHlr:Function;
            var autoData:Object;
            var iAutoClose:* = param1;
            rollOverHlr = function (event:MouseEvent) : void
            {
                removeTimer();
                listener.removeEventListener(MouseEvent.MOUSE_OVER, rollOverHlr);
                return;
            }// end function
            ;
            rollOutHlr = function (event:MouseEvent) : void
            {
                listener.addEventListener(MouseEvent.MOUSE_OVER, rollOverHlr);
                removeTimer();
                var _loc_2:* = new Timer(iAutoClose.getCloseTime(), 1);
                _loc_2.addEventListener(TimerEvent.TIMER_COMPLETE, timerHlr);
                iAutoClose.autoData.timer = _loc_2;
                iAutoClose.autoData.timerHlr = timerHlr;
                _loc_2.start();
                return;
            }// end function
            ;
            timerHlr = function (event:TimerEvent) : void
            {
                removeTimer();
                listener.removeEventListener(MouseEvent.MOUSE_OVER, rollOverHlr);
                iAutoClose.autoClose();
                return;
            }// end function
            ;
            var removeTimer:* = function () : void
            {
                var _loc_1:* = iAutoClose.autoData.timer;
                if (_loc_1)
                {
                    _loc_1.stop();
                    _loc_1.removeEventListener(TimerEvent.TIMER_COMPLETE, timerHlr);
                    iAutoClose.autoData.timer = null;
                    iAutoClose.autoData.timerHlr = null;
                }
                return;
            }// end function
            ;
            listener = iAutoClose.getSkin();
            if (listener)
            {
                autoData = iAutoClose.autoData;
                autoData.timer = null;
                autoData.timerHlr = null;
                autoData.rollOverHlr = rollOverHlr;
                autoData.rollOutHlr = rollOutHlr;
                listener.addEventListener(MouseEvent.ROLL_OUT, rollOutHlr);
            }
            return;
        }// end function

        public static function removeBehavior(param1:IAutoClose) : void
        {
            var _loc_4:Timer = null;
            var _loc_2:* = param1.getSkin();
            var _loc_3:* = param1.autoData;
            if (_loc_2)
            {
                if (_loc_3.rollOutHlr)
                {
                    _loc_2.removeEventListener(MouseEvent.ROLL_OUT, _loc_3.rollOutHlr);
                }
                if (_loc_3.rollOverHlr)
                {
                    _loc_2.removeEventListener(MouseEvent.ROLL_OVER, _loc_3.rollOverHlr);
                }
                _loc_4 = _loc_3.timer;
                if (_loc_4)
                {
                    _loc_4.stop();
                    if (_loc_3.timerHlr)
                    {
                        _loc_4.removeEventListener(TimerEvent.TIMER_COMPLETE, _loc_3.timerHlr);
                    }
                    _loc_3.timer = null;
                    _loc_3.timerHlr = null;
                }
                delete _loc_3.rollOutHlr;
                delete _loc_3.rollOverHlr;
                delete _loc_3.timer;
                delete _loc_3.timerHlr;
            }
            return;
        }// end function

    }
}
